#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
typedef struct LisNode {
    int data;
    struct LisNode* next;
}LisNode;
LisNode* BuyNewNode(int x)
{
    LisNode* head = (LisNode*)malloc(sizeof(LisNode));
    head->data = x;
    head->next = NULL;
    return head;
}
LisNode* CreatList(int n) {
    LisNode* head = BuyNewNode(1);
    LisNode* foot = head;
    int i;
    for (i = 2; i <= n; i++)
    {
        foot->next = BuyNewNode(i);
        foot = foot->next;
    }
    foot->next = head;
    return foot;
}
int main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    
    LisNode* ptail = CreatList(n);
    LisNode* phead = ptail->next;
    int count = 1;
    while (phead->next != phead)
    {
        if (count == q)
        {
            ptail->next = phead->next;
            free(phead);
            phead = ptail->next;
            count = 1;
        }
        else {
            ptail = phead;
            phead = phead->next;
            count++;
        }

    }
    printf("%d", phead->data);
    return 0;
}